<template>
  <div class="cont">
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="id" label="id" width="180" />
      <el-table-column prop="username" label="会员名称" width="180" />
      <el-table-column prop="last_login_time" label="最近登录" />
      <el-table-column prop="last_login_ip" label="登录ip" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button @click="editAdmin(scope.row)" size="small">编辑</el-button>
          <el-button @click="deleteAdmin(scope.row)" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { getAdminList ,deleteAdminApi } from '@/api/setting'
export default {
  name:'admin',
  data(){
    return {
      tableData:[
        {
          id:'1',
          username:'w',
          last_login_time:'2020-02-02',
          last_login_ip:'192.168.1.1',
          
        }
      ]
    }
  },
  mounted(){
    this.init()
  },
  methods:{
    async init(){
      let res = await getAdminList()
      this.tableData = res.data
    },
    editAdmin(row){
      this.$router.push('/setting/editAdmin?id='+row.id)
    },
    async deleteAdmin(row){
      
      this.$confirm('确定要删除该管理员吗？',{
        cancelButtonText:'取消',
        confirmButtonText:'确定',
      }).then(()=>{
        deleteAdminApi({id:row.id}).then(res=>{
          console.log('res:',res)
          if(res.code === 0){
            this.init()
          }
        })
      })
      
    }
  }
}
</script>

